﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% var profile = Profile.GetProfile(User.Identity.Name);   %>
    <table class="tftable" title="ข้อมูลผู้ร้องขอ"  style="width: 95%" >
    <tr style="background-color:#929097; color:White;"><td colspan="2"><h3>ข้อมูลผู้ร้องขอ</h3></td></tr>
        <tr>
            <th>
               <h3> รหัสพนักงาน</h3>
            </th>
            <td><%: profile.Empcode %>
            </td>
        </tr>
        <tr>
            <th style="width: 25%">
                <h3>
                    ชื่อพนักงาน</h3>
            </th>
            <td>
                <%: profile.FullName %>
            </td>
        </tr>
        <tr>
            <th class="txt_right">
                <h3>
                    แผนก</h3>
            </th>
            <td>
                <select id="cboDep"  multiple="multiple">
                </select>
                <input type="hidden" id="hdndep" />
            </td>
        </tr>
        <tr>
            <th class="txt_right">
                <h3>
                    ผู้จัดการแผนก</h3>
            </th>
            <td>
                <select id="cboMgr"  multiple="multiple">                  
                </select><input type="hidden" id="hdnMgr" /><input type="hidden" id="hdnMemail" />
            </td>
        </tr>
    </table>
    <br />
    <table style="width: 95%" class="tftable">
         <tr style="background-color:#929097; color:White;"><td colspan="2"><h3>ข้อมูลเพิ่มเติม</h3></td></tr>
<tr>
            <th>
                <h3>
                    หัวข้ออนุมัติ</h3>
            </th>
            <td>
                <h3>จัดทำเอกสาร และข้อมูลใหม่</h3>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ประเภทเอกสารและข้อมูล</h3>
            </th>
            <td>
                <select id="cbodoc">
                    <option value=""></option>
                </select>
            </td>
        </tr>
        
        <tr>
            <th>
                <h3>
                    เอกสารที่ต้องการอนุมัติ</h3>
            </th>
            <td>
                <div id="attachment1">
                </div>
            </td>
        </tr>
        <tr>
            <th style="vertical-align: top;">
                <h3>
                    รายละเอียด/เหตุผลของการอนุมัติ</h3>
            </th>
            <td>
                                       
            <textarea id="txtReason" rows="5" cols="75" class="resizable"></textarea>                 
            
            </td>
        </tr>
        <tr>
            <th style="width: 25%">
                <h3>
                    ระบุความสัมพันธ์กับเอกสารอื่น
                </h3>
            </th>
            <td>
                <%--       <div class="t-button" style="padding: 5px 20px;">
                    Select Master</div>--%>
                <select id="cboRevdoc" multiple="multiple">
                </select>
            </td>
        </tr>
        <tr>
            <th style="width: 25%">
                <h3>
                    ระบุเอกสาร revision ก่อนหน้า
                </h3>
            </th>
            <td>
                <input type="text" id="txtrev" />
            </td>
        </tr>
        <tr>
            <th style="width: 25%">
            </th>
            <td>
        
                <input type="button" id="btnSend" value="Send Document" class="btn" />
                <%-- <input type="button" id="btnRej" value="Reject Document" class="btn" />--%>
            </td>
        </tr>
    </table>
    <div id="dialog" title="SendDocument">
        <h3 style="color: #000">
            <div>
                สามารถติดตามงานได้ที่</div>
            <br />
            <div id="darno">
            </div>
            <div>
                Document during approve/correct from approval</div>
        </h3>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <h2>
        จัดทำเอกสาร และข้อมูลใหม่</h2>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
<% if (false)
   { %>
    <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <%} %>
    <style>
        select, input[type=text]
        {
            width: 300px;
        }

    </style>
    <script src="<%: Url.Content("~/Scripts/telerik.common.min.js")%>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/telerik.upload.min.js")%>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery.multiple.select.js")%>" type="text/javascript"></script>
    <link href="<%: Url.Content("~/Content/themes/telerik.comcustommon.min.css")%>" rel="stylesheet"     type="text/css" />
            <link href="<%: Url.Content("~/Content/multiple-select.css")%>" rel="stylesheet"   type="text/css" />
    <link href="<%: Url.Content("~/Content/themes/telerik.common.min.css")%>" rel="stylesheet"       type="text/css" />
    <link href="<%: Url.Content("~/Content/themes/metro/telerik.metro.min.css")%>" rel="stylesheet"      type="text/css" />
<style type="text/css">
    .ui-widget-content
    {
        color: #000 !important;
        border-color: #999;
        border:0px solid;
    }
    #txt
    {
        border: 1px solid #999;
    }
</style>
    <script type="text/javascript">

        $(function () {

            // var upload = $("#attachment").upload({ uploadUrl: '<%:Url.Action("Upload") %>', downloadUrl: '<%:Url.Action("DownloadTemp") %>' });
            var upload1 = $("#attachment1").upload({ uploadUrl: '<%:Url.Action("Upload1") %>', downloadUrl: '<%:Url.Action("DownloadTemp") %>', multiple: false });
            $.post('<%=Url.Action("List_Depart","NewReq") %>', function (data) {
                $.each(data, function (val, text) {
                    text = $.trim(text);
                    $("#cboDep").append($('<option></option>').val(text).html(text));
                });
                $('#cboDep').multipleSelect({ filter: true, single: true, placeholder: "แผนก"
                , onClick: function () {                    
                    $("#hdndep").val($("#cboDep").multipleSelect("getSelects"));
                }
                , onOpen: function () {
                    $("#cboDep").multipleSelect("setSelects", [$("#hdndep").val()]);
                }
                });
            });
         // Manager  hdnMemail
            $.post('<%=Url.Action("List_Manager","NewReq") %>', function (data) {
                for (var i = 0; i < data.length; i++) {
                    $("#cboMgr").append($('<option></option>').val(data[i][0]._Code).html(data[i][0]._Type));
                }
                $('#cboMgr').multipleSelect({ filter: true, single: true, placeholder: "ผู้จัดการแผนก"
                , onClick: function () {
                    $("#hdnMemail").val($("#cboMgr").multipleSelect("getSelects"));
                    $("#hdnMgr").val($("#cboMgr").multipleSelect("getSelects", "text"));
                }
                , onOpen: function () {
                    $("#cboMgr").multipleSelect("setSelects", [$("#hdnMgr").val()]);
                } 
                });
            });
            // Problem
            $.post('<%=Url.Action("ListDOC_TYPE","Master") %>', function (data) {

                for (var i = 0; i < data.length; i++) {
                    $("#cbodoc").append($('<option></option>').val(data[i]._Code).html(data[i]._Type));
                }
                ;
            });
            // DarList
            //            $.post('<%=Url.Action("List_Darno","NewReq") %>', function (data) {
            //                for (var i = 0; i < data.length; i++) {
            //                    $("#cboRevdoc").append($('<option></option>').val(data[i]._Docno).html(data[i]._Docno));
            //                }
            //                $('#cboRevdoc').multipleSelect();
            //            });

            $('#txtrev').autoNumeric({ vMin: '0', vMax: '999', aPad: false });
            function valid_data() {

                if ($("#hdndep").val().length <= 0) {
                    $().toastmessage('showErrorToast', "เลือกแผนก");
                    $("#cboDep").focus();
                    return false;
                }
                if ($("#hdnMemail").val().length <= 0) {
                    $().toastmessage('showErrorToast', "เลือกผู้จัดการแผนก");
                    $("#cboMgr").focus();
                    return false;
                }
                if ($("#cbodoc").val().length <= 0) {
                    $().toastmessage('showErrorToast', "เลือกประเภทเอกสารและข้อมูล");
                    $("#cbodoc").focus();
                    return false;
                }

                var files = upload1.getFiles();
                if (files.length <= 0) {
                    $().toastmessage('showErrorToast', "ระบุเอกสารที่ต้องการอนุมัติ");
                    return false;
                }
            }
            $("#btnSend").click(function () {
                if (valid_data() == false) return;
                var files = upload1.getFiles();

                var dataForSubmit = new Array();
                dataForSubmit.push({
                    _Dep: $("#hdndep").val(),
                    _Mgrname: $("#hdnMgr").val(),
                    _Mgremail: $("#hdnMemail").val(),
                    _DOCType: $("#cbodoc").val(),
                    _OPTType: '<%: ISODOC.Models.SessionBag.Current.opt  %>',
                    _Filename: files[0].fileName,
                    _FileTemp: files[0].fileTempName,
                    _Text: $("#txtReason").html(),
                    _Refrev: $("#txtrev").val(),
                    _Refdocid: $('#cboRevdoc').val(),
                    _Text: $("#txtReason").val()
                })
                var getUsersUrl = '<%= Url.Action("Save_Req") %>'; WAITINGDLG_show(imgWait);
                callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
            });

            function callScriptMethod(url, jsonObject, action, callback, async) {

                callback = callback || function () { };
                async = (async == null || async);

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: url,
                    data: JSON.stringify(jsonObject),
                    dataType: "json",
                    async: async,
                    success: function (data) {

                        if (data.success != "0") {
                            //OK 
                            $("#darno").html("DAR NO." + data.message);
                            $("#dialog").dialog("open");
                        } else $().toastmessage('showErrorToast', data.message);
                        WAITINGDLG_hide();
                    },
                    error: function (xhr, status, error) {
                        var err = xhr.responseText;
                        alert(err.Message);
                    }

                });
                // 
            }

            $("#dialog").dialog({
                width: 350,
                height: 250,
                autoOpen: false,
                show: "blind",
                buttons: {

                    "OK": function () {

                        $("#dialog").dialog("close");
                    }
                }
            });
           

        });
    </script>
</asp:Content>
